<template>
	<view class="">
		<view class="wallet_bg">
			<view class="top_box jui_bg_fff jui_mar_2432 jui_flex_col_center">
				<view class="jui_h30">

				</view>
				
				<view class="jui_h60"></view>
				<view class="jui_flex  jui_flex_items_center justify-between jui_pad_t20"  style="margin-bottom: 50px;">
					
					<text style="width: 100%;">我的资金：<text style="font-size: 22px; font-weight: 800;">{{userinfo.money}}</text></text>
				</view>
				<view class="jui_flex  jui_flex_items_center justify-between jui_pad_t20" v-for="(item,index) in task.inputItems" 	>
					
					<text style="width: 80%; margin-left: 20px; font-size: 32rpx;">阶段{{index+1}}: {{item.text}}, 金额：{{item.price}} , 已筹：{{item["get_price"]|| 0}}, 是否可投：{{item["status"]===1}}</text>
					
				</view>
				
				<view class="jui_flex  jui_flex_items_center justify-between jui_pad_t20" style="margin-top: 100px;">
					
					<text style="width: 30%;">投资金额：</text>
					<input type="number" maxlength="6" value="" placeholder="请输入金额" v-model="pass_phrase" style="width: 70%;"/>
				</view>
				<view class="zhuse  shouquan" @tap='chongzhi'>
					投资
				</view>
			</view>
			
		</view>

		<view class="" style="height: 3200rpx;">

		</view>

	</view>
</template>

<script>
	import tkiQrcode from "@/components/tki-qrcode/tki-qrcode.vue"
	import vNavigation from '@/components/navigation/navigation.vue'
	export default {
		components: {
			vNavigation,
			tkiQrcode
		},
		data() {
			return {
				userinfo: {},
				task_id:'',
				task: {},
				lcb_index: 0,
				val: '1', // 要生成的二维码值
				size: 300, // 二维码大小
				unit: 'upx', // 单位
				background: '#b4e9e2', // 背景色
				foreground: '#309286', // 前景色
				pdground: '#32dbc6', // 角标色
				icon: '', // 二维码图标
				iconsize: 40, // 二维码图标大小
				lv: 3, // 二维码容错级别 ， 一般不用设置，默认就行
				onval: true, // val值变化时自动重新生成二维码
				loadMake: false, // 组件加载完成后自动生成二维码
				src: '' ,// 二
				url:'',
				pass_phrase: 100,
			}
		},
		onLoad(opt) {
			this.task_id = opt.task_id
		},
		onShow() {
			this.getMoney()
			this.getTask()
		},	
		methods: {
			chongzhi(){
				
				var status = 0
				for(var i=0;i<this.task.inputItems.length;i++){
					var lcb = this.task.inputItems[i]
					if(lcb['status'] == 1){
						status =1
						this.lcb_index = i
					}
				}
				if(status==0){
					uni.showToast({
						title:'\n项目里程碑暂未启动！不能投资',
						icon:'error',
						duration: 3500
					})
					return
				}
				
				if(this.pass_phrase <= this.userinfo.money){
					var that = this
					this.$api.task_touzi({money:this.pass_phrase, user_id:uni.getStorageSync('loginInfo').user_id, mobile:uni.getStorageSync('loginInfo').mobile,
										lcb_index:that.lcb_index,task_id:that.task_id}).then(res => {
						if (res.code == 10000) {
							var l = uni.getStorageSync('loginInfo')
							l.money = res.data.des
							uni.setStorageSync('loginInfo.money',res.data.des)
							uni.reLaunch({
								url:'/pages/task/commodity_details/touzi?task_id='+ that.task_id
							})
						}else{
							uni.showToast({
								title:res.msg,
								icon:'error',
								duration: 2500
							})
						}
					});
				}else{
					uni.showToast({
						title:'投资金额不能大于我的资金',
						icon:'error',
						duration: 2500
					})
					return
				}
				
			},
			getMoney(){
				var that=this
				this.$api.getMoney({user_id:uni.getStorageSync('loginInfo').user_id}).then(res => {
					if (res.code == 10000) {
						that.userinfo = res.data;
						uni.setStorageSync('loginInfo',res.data);
					}
				});
			},
			getTask(){
				var that=this
				this.$api.get_task_detail({task_id:that.task_id}).then(res => {
					console.log(res)
					if (res.code == 10000) {
						that.task = res.data.task;
					}
				});
			},
			getJobConfig(){
				this.$api.getJobConfig({data:1}).then(res => {
					if (res.code == 1) {
						this.content = res.data.recharge_notice ;
					}
				});
			},
			address(){
				let data = {
					type:'trc',
					FromToken:this.FromToken
				}
				this.$api.getWallet(data).then(res => {
					if (res.code == 1) {
						this.wallet = res.data.wallet;
						this.url = res.data.wallet.address;
						// this.url = 'kjhgfdsytreytr';
						this.val = this.url;
						this.$refs.qrcode2._makeCode();
					}
				});
				
			},
			text(){
				this.$api.getRechargeNotice().then(res => {
					this.content = res.data
				});
			},
			chooseTab(index){
				if(index == 1){
					this.$msg('暂未开通')
				}else {
					this.tabindex = index;
				}
			},
			qrR(res) {
				this.src = res
				console.log(res)
			},
			clearQrcode() {
				this.$refs.qrcode._clearCode()
				this.val = ''
			},
			ifQrcode() {
				this.ifShow = !this.ifShow
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #FFFFFF;
	}

	.copy {
		height: 56rpx;
		border-radius: 8px;
		background-color: rgba($color: #000000, $alpha: 0.09);
		font-size: 26rpx;
		width: 156rpx;
		text-align: center;
		line-height: 56rpx;
	}

	.top_list {
		width: 100%;
	}

	.on {
		color: $zhuse;
		background-color: rgba($color: $zhuse, $alpha: 0.09);

	}

	.off {
		background-color: #F5F5F5;
	}

	.topPlace {
		width: 100%;
		height: var(--status-bar-height);
		background: $zhuse;

	}

	.wallet_bg {
		height: 200rpx;
		background:$zhuse;
		// border-radius: 0px 0px 100rpx 100rpx;
		position: relative;

		.top_box {
			position: absolute;
			top: 20rpx;
			width: 698rpx;
			height: 682px;
			background: #FFFFFF;
			box-shadow: 0px 0px 20rpx 0px rgba(0, 0, 0, 0.1);
			border-radius: 32rpx;
		}
	}

	.box {
		width: 258rpx;
		height: 88rpx;
		border-radius: 16rpx;
		background-color: rgba($color: #5B08BE, $alpha: 0.09);
		justify-content: space-around;
		align-items: center;
	}
	.shouquan {
		margin-top: 50px;
		width: 50%;
		height: 82rpx;
		background: $zhuse;
		border-radius: 20rpx;
		line-height: 82rpx;
		text-align: center;
		color: #FFFFFF;
	}
</style>
